<template>
	<view class="content">
		<view class="search">
			<view class="search-box">
				<my-search :bgcolor="'#ffffff'" @mySearch="gotoSearch"></my-search>
			</view>
			<!-- <u-search border-color="#f4f5f9" search-icon-color="#FF6666" placeholder="关键词" v-model="keyword" @search="search"
        @custom="search"></u-search> -->
		</view>

		<view class="wrap">
			<u-swiper :list="swiperList" height="350" @click="swiperClick"></u-swiper>
		</view>
		<!-- 分类导航区域 -->
		<ju-navigator-grid element-id="navigatorMenu" :list="menu" @press="onPress" height="150" size="60" />
		<!-- 商圈头条 -->
		<view class="business-top">
			<view class="title">
				商业头条 |
			</view>
			<view class="srcoll">
				<u-notice-bar :is-circular="false" :volume-icon="false" more-icon="true" mode="horizontal" type="none"
					:list="navSQList" @getMore="gotoIndustryDynamicInfo(3)"></u-notice-bar>
			</view>
		</view>

		<view class="leadnews">
			<view class="leadnews_title">
				<view class="leadnews_title_name">
					<text>行业动态</text>
				</view>
				<view class="leadnews_title_more" @click="gotoIndustryDynamicInfo(0)">
					<text>查看更多</text>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>

			<!-- 基于 uni-list 的页面布局 -->
			<view class="leadnews_box" v-for="(item,index) in navDTList" :key="index" @click="gotoDetail(item)">
				<view class="leadnews_box_left">
					<view class="leadnews_box_left_name">
						<text>{{item.articleTitle}}</text>
					</view>
					<view class="leadnews_box_left_time">
						<text>{{item.createTime}}</text>
					</view>
				</view>
				<view class="leadnews_box_img">
					<u-image width="100%" height="100%" :src="url+item.materialUrl"></u-image>
				</view>
			</view>
		</view>

		<!-- 招标信息 -->
		<view class="leadnews">
			<view class="leadnews_title">
				<view class="leadnews_title_name">
					<text>招标信息</text>
				</view>
				<view class="leadnews_title_more" @click="gotoIndustryDynamicInfo(1)">
					<text>查看更多</text>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="leadnews_title_content" v-for="(item,index) in navZBList" :key="index"
				@click="gotoDetail(item)">
				<view class="leadnews_title_content_name">
					<text>{{item.articleTitle}}</text>
				</view>
				<view class="leadnews_title_content_time">
					<text>{{item.createTime }}</text>
				</view>
			</view>
		</view>
		<!-- 热门话题 -->
		<!-- <view class="leadnews">
			<view class="leadnews_title">
				<view class="leadnews_title_name">
					<text>热门话题</text>
				</view>
				<view class="leadnews_title_more" @click="gotoIndustryDynamicInfo(2)">
					<text>查看更多</text>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="sugg-list">
				<view class="sugg-item" v-for="(item,index) in navRMList" :key="index" @click="gotoDetail(item)">
					<view class="goods-name">
						{{item.articleTitle}}
					</view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
		</view> -->

		<u-tabbar v-model="current" :list="tablist" :beforeSwitch="beforeSwitch" :mid-button="true"></u-tabbar>
		<u-popup v-model="show" mode="bottom">

			<view class="contentBox">
				<!-- <image class="logo" :class="{'active':active}" src="../../static/nav_icon/fenxiang@2x.png"  mode="aspectFit"></image> -->
				<view class="tabbar-box-wrap">
					<view class="tabbar-box">
						<view class="tabbar-box-item" @click="goToPage('/subpackage/technology_share/share_new')">
							<image class="box-image" src="../../static/nav_icon/fenxiang@2x.png" mode="aspectFit">
							</image>
							<text class="explain">技术分享</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/technology_share/share_new_fault')">
							<image class="box-image" src="../../static/nav_icon/shebeifuwu@2x.png" mode="aspectFit">
							</image>
							<text class="explain">消缺支援</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/wind/build/build_demand')">
							<image class="box-image" src="../../static/nav_icon/offshore_wind.png" mode="aspectFit">
							</image>
							<text class="explain">建设需求</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/wind/build/build_service')">
							<image class="box-image" src="../../static/nav_icon/secondarymarket@3x.png"
								mode="aspectFit"></image>
							<text class="explain">设备服务</text>
						</view>
					</view>
					<view class="close_dialog">
						<view class="closeBox" @click="beforeSwitch(2)">
							<u-icon name="close"></u-icon>
						</view>
					</view>
				</view>
			</view>

			<!-- <view
				style="display: flex;flex-direction: column;background: #666666;height: 100vh;justify-content: center;align-items: center;">
				<view style="display: flex;flex-direction: column;align-items: center;background: #666666;width: 300rpx;">

					<view style="display: flex;flex-direction: column;"
						@click="goToPage('/subpackage/technology_share/share_new')">
						<image style="width: 100rpx;height: 100rpx;" src="/static/nav_icon/fenxiang@2x.png"
							mode="aspectFit"></image>
						<text class="explain">技术分享</text>
					</view>
					<view style="display: flex;flex-direction: column;"
						@click="goToPage('/subpackage/technology_share/share_new_fault')">
						<image style="width: 100rpx;height: 100rpx;" src="/static/nav_icon/shebeifuwu@2x.png"
							mode="aspectFit"></image>
						<text class="explain">消缺支援</text>
					</view>
					<view style="display: flex;flex-direction: column;"
						@click="goToPage('/subpackage/wind/build/build_demand')">
						<image style="width: 100rpx;height: 100rpx;" src="/static/nav_icon/offshore_wind.png"
							mode="aspectFit"></image>
						<text class="explain">建设需求</text>
					</view>
					<view style="display: flex;flex-direction: column;"
						@click="goToPage('/subpackage/wind/build/build_service')">
						<image style="width: 100rpx;height: 100rpx;" src="/static/nav_icon/secondarymarket@3x.png"
							mode="aspectFit">
						</image>
						<text class="explain">设备服务</text>
					</view>
					<view style="width: 100rpx;height: 100rpx;background-color:white;border-width: 1rpx;" @click="beforeSwitch">关闭</view>
				</view>
			</view> -->

		</u-popup>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	let WebIM = require("../../utils/WebIM.js")["default"];

	export default {
		data() {
			return {
				isDot: false,
				active: false,
				tablist: [

					{
						iconPath: "/static/tabbar_icon/home@2x.png",
						selectedIconPath: "/static/tabbar_icon/home-active@2x.png",
						text: '首页',
						customIcon: false,
						pagePath: "/pages/home/home",
					},
					{
						iconPath: "/static/tabbar_icon/topic@2x.png",
						selectedIconPath: "/static/tabbar_icon/topic-active@2x.png",
						text: '话题',
						pagePath: "/pages/topic/topic",
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '发布',
						midButton: true,
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar_icon/message@2x.png",
						selectedIconPath: "static/tabbar_icon/message-active@2x.png",
						text: '消息',
						isDot: false,
						count: '',
						customIcon: false,
						pagePath: "/pages/commentsmsg/commentsmsg",
					},
					{
						iconPath: "/static/tabbar_icon/my@2x.png",
						selectedIconPath: "/static/tabbar_icon/my-active@2x.png",
						text: '我的',

						isDot: false,
						customIcon: false,
						pagePath: "/pages/myuser/myuser",
					},
				],


				keyword: '',
				list: [],
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
				show: false,
				activityList: [],

				params: {
					categoryId: 0,
					pageNum: 1,
					pageSize: 3,
				},
				menu: [], //  导航菜单
				swiperList: [], // 轮播图
				navSQList: [], // 商圈list
				navDTList: [], // 行业动态
				navZBList: [], // 招标信息list
				navRMList: [], // 热门话题list
				url: this.baseUrl
			};
		},
		onLoad() {
			this.menu = this.getMenu;
			this.loginInit();

			var that = this;
			this.timer = setInterval(() => {

				if (this.$store.state.isLogin) {
					this.$u.api.getWindCommentsMsgDots({
							userId: this.$store.state.userinfo.id,
						})
						.then(res => {

							if (res.data > 0) {
								that.tablist[3].isDot = true;

								that.tablist[3].count = 1;

							} else {
								that.tablist[3].isDot = false;

								that.tablist[3].count = 0;
							}

						});
				}

			}, 5000);
		
		
		},
		onShow() {
			//this.tablist[3].isDot=true;
			// if (this.$store.state.isLogin) {

			// 	this.imlogin(this.$store.state.userinfo.phoneNumber, this.$store.state.userinfo.nickname);

			// }
			this.init();

		},
		computed: {
			...mapGetters(['getUserinfo', 'getNeedAuth', 'getIsLogin', 'getMenu'])
		},

		methods: {
			...mapActions(['login', 'authUserInfo']),
			init() {
				this.listArticleInfo(0);
				this.listArticleInfo(1);
				// this.listArticleInfo(2);
				this.listArticleInfo(3);
				this.listArticleInfo(4);

			},
			loginInit() {
				this.login().then((data) => {
					if (data != null) {
						uni.setStorageSync("userinfo", data);
						//this.imlogin(data.phoneNumber, data.nickname);
					}
					// if (this.$store.state.isLogin) {
					// }
				});

			},
			gotoSearch() {
				uni.navigateTo({
					url: '/subpackage/search/search'
				})
			},
			swiperClick(index) {

				var detail = '/subpackage/industry_dynamic_detail/industry_dynamic_detail?articleId=' + this.swiperList[
					index].id;
				uni.navigateTo({
					url: detail
				});

			},
			search() {},
			// 对应没有openType和url时的点击事件

			imlogin(username, nickname) {
				const that = this;
				var options = {
					apiUrl: WebIM.config.apiURL,
					username: username,
					password: username,
					nickname: nickname,
					appKey: WebIM.config.appkey,
					success: function(res) {
						uni.showToast({
							title: "注册成功"
						});
						uni.setStorage({
							key: "myUsername",
							data: username
						});


						getApp().globalData.conn.open({
							apiUrl: WebIM.config.apiURL,
							user: username,
							pwd: username,
							grant_type: "password",
							appKey: WebIM.config.appkey
						});
					},
					error: function(res) {

						if (res.statusCode !== "200") {
							if (res.statusCode == '400' && res.data.error == 'illegal_argument') {
								return;
							}

							uni.setStorage({
								key: "myUsername",
								data: username
							});

							getApp().globalData.conn.open({
								apiUrl: WebIM.config.apiURL,
								user: username,
								pwd: username,
								grant_type: "password",
								appKey: WebIM.config.appkey
							});

						}
					}
				};
				WebIM.conn.registerUser(options);


			},

			// 跳转到商业头条 界面
			gotoIndustryDynamicInfo(type) {
				uni.navigateTo({
					url: '/subpackage/industry_dynamic_info/industry_dynamic_info?type=' + type
				})
			},
			change(index) {
				alert(index);
			},
			goToPage(url) {
				if (!url) return;
				uni.navigateTo({
					url
				});
			},
			beforeSwitch(index) {
				if (index == 2) {
					this.show = !this.show;
				}
				return true;
			},

			//  跳转到详情页
			gotoDetail(item) {
				uni.navigateTo({
					url: '/subpackage/industry_dynamic_detail/industry_dynamic_detail?articleId=' + item.articleId
				})
			},
			// 获取分类频道信息内容
			listArticleInfo(categoryId) {

				this.params.categoryId = categoryId
				if (categoryId == 4) {
					this.params.pageNum = ''
					this.params.pageSize = ''
				}
				this.$u.api.article.articleTypeList(this.params)
					.then(res => {
						if (res.code != '200') return this.$u.toast(res.msg);
						if (categoryId == 0) {
							this.navDTList = res.rows.splice(0, 3)
						} else if (categoryId == 1) {
							this.navZBList = res.rows.splice(0, 3)
						}  else if (categoryId == 3) {
							//this.navSQList   = res.rows;
							this.navSQList = [];
							for (var i = 0; i < res.rows.length; i++) {
								var title = res.rows[i].articleTitle;
								this.navSQList.push(title);
							}
						} else if (categoryId == 4) {
							this.swiperList = [];
							for (var i = 0; i < res.rows.length; i++) {
								let param = {
									id: res.rows[i].articleId,
									title: res.rows[i].articleTitle,
									image: this.baseUrl + res.rows[i].materialUrl,
								}
								this.swiperList.push(param)
							}
						}
					});
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background-color: #F7F7F7;

		.search {
			//margin: 10rpx 20rpx;
		}

		.wrap {
			height: 300rpx;
			margin-bottom: 80rpx;
		}

		// 商圈头条
		.business-top {
			background-color: #FF5A5F;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			background-color: #E8F0F8;
			margin-left: 50rpx;
			margin-right: 50rpx;
			margin-top: 20rpx;
			margin-bottom: 20rpx;
			border-radius: 10rpx;

			.title {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #3BA2FF;
				line-height: 48rpx;
			}

			.srcoll {
				width: 500rpx;
			}
		}

		// 招标信息


		.uni-list-box {
			margin-top: 0;
		}

		.uni-content {
			padding-right: 10px;
		}

		.uni-note {
			display: flex;
			margin: 0;
			justify-content: space-between;
		}


		//leadnews
		.leadnews {
			margin-bottom: 20rpx;
			background-color: #FFFFFF;

			.leadnews_title {
				height: 80rpx;
				line-height: 80rpx;
				display: flex;
				justify-content: space-between;
				margin: 0rpx 30rpx;

				.leadnews_title_name {
					text {
						font-size: 40rpx;
						font-weight: bold;
					}
				}

				// 查看更多
				.leadnews_title_more {
					text {
						color: #666666;
						font-size: 26rpx;
					}
				}
			}
		}

		.leadnews_box {
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #E5E5E5;
			height: 200rpx;
			margin: 20rpx;

			.leadnews_box_left {
				width: 70%;
				height: 160rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.leadnews_box_left_name {
					height: 95rpx;
					line-height: 50rpx;
					text-overflow: -o-ellipsis-lastline;
					letter-spacing: 3rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}

			.leadnews_box_img {
				width: 30%;
				height: 160rpx;
			}
		}

		//招标信息
		.leadnews_title_content {
			height: 150rpx;
			margin: 0rpx 20rpx;
			border-bottom: 1px solid #E5E5E5;

			.leadnews_title_content_name {
				font-size: 26rpx;
				color: #333333;
				height: 80rpx;
				line-height: 80rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.leadnews_title_content_time {
				font-size: 24rpx;
				color: #999999;
				float: right;
			}
		}

		// 热门话题
		.sugg-list {
			padding: 0 10rpx;

			.sugg-item {
				font-size: 28rpx;
				padding: 20rpx 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				image {
					width: 50rpx;
					height: 50rpx;
				}

				.goods-name {
					// 文字不允许换行（单行文本）
					white-space: nowrap;
					// 溢出部分隐藏
					overflow: hidden;
					// 文本溢出后，使用 ... 代替
					text-overflow: ellipsis;
					margin-right: 6rpx;
				}
			}
		}


	}



	.contentBox {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		/* #ifdef H5 */
		height: calc(100vh - var(--window-bottom) - var(--window-top));
		/* #endif */
		/* #ifndef H5 */
		height: 100vh;
		/* #endif */
		transition: opacity 0.3s;
		background: #333333;

		// opacity: 0;
		// &.active {
		// 	opacity: 1;
		// }
		.logo {
			position: relative;
			margin-top: -400upx;
			width: 200upx;
			height: 200upx;
			// z-index: -1;
			opacity: 0;
			transition: opacity 0.3s;

			&.active {
				opacity: 1;
			}
		}
	}

	.tabbar-box-wrap {
		position: absolute;
		width: 100%;
		padding: 50upx;
		box-sizing: border-box;
		bottom: 0;
		left: 0;

		.tabbar-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;
			display: flex;
			width: 100%;
			// background: #fff;
			// border-radius: 20upx;
			padding: 15upx 20upx;
			box-sizing: border-box;
			z-index: 2;

			// box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.1);
			// &:after {
			// 	content: '';
			// 	position: absolute;
			// 	bottom: -16upx;
			// 	left: 0;
			// 	right: 0;
			// 	margin: auto;
			// 	width: 50upx;
			// 	height: 50upx;
			// 	transform: rotate(45deg);
			// 	background: #fff;
			// 	z-index: 1;
			// 	box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.1);
			// 	border-radius: 2px;
			// }
			// &:before {
			// 	content: '';
			// 	position: absolute;
			// 	top: 0;
			// 	left: 0;
			// 	width: 100%;
			// 	height: 100%;
			// 	background: #ffffff;
			// 	border-radius: 20upx;
			// 	z-index: 2;
			// }
			.tabbar-box-item {
				display: flex;
				align-items: center;
				width: 46vw;
				//justify-content: center;
				// position: relative;
				// width: 100%;
				z-index: 3;
				margin: 40upx auto;
				color: $uni-color-subtitle;
				text-align: center;
				font-size: 100vw;
				justify-content: space-around;

				.box-image {
					width: 15vw;
					height: 15vw;
				}

				.explain {
					color: #FFFFFF;
					font-size: 7vw;
				}
			}
		}
	}

	.close_dialog {
		height: 100rpx;
		display: flex;
		justify-content: center;
		margin-top: 40rpx;

		.closeBox {
			background: #FFFFFF;
			margin: auto;
			border-radius: 50%;
			text-align: center;
			height: 100rpx;
			line-height: 100rpx;
			width: 100rpx;

		}
	}
</style>
